package homevideo_model

import (
	"encoding/json"
	"fmt"
	"iptv_server/v3/src/database"
	"iptv_server/v3/src/mydebug"
	"testing"
)

func TestDetail_Create(t *testing.T) {
	mydebug.InitDB()
	database.DB.AutoMigrate(new(Detail))
	database.DB.AutoMigrate(new(Play))
	pics := []string{
		"http://server.lan:9966/videos/12_tv2/%E4%B8%89%E5%9B%BD%E6%BC%94%E4%B9%89.1994/__poster.jpg",
		"http://server.lan:9966/videos/12_tv2/%E8%B4%9E%E8%A7%82%E4%B9%8B%E6%B2%BB%202006/__poster.jpg",
	}
	t.Run("tt.name", func(t *testing.T) {
		count := 0
		for i := range 2 {
			for j := 1; j < 5; j++ {
				d := &Detail{
					CategoryID:  uint(i + 1),
					Name:        fmt.Sprintf("my2 name%d", i),
					Pic:         pics[i%len(pics)],
					Year:        string(j),
					Remark:      fmt.Sprintf("my name%d_%d", i, j),
					Area:        fmt.Sprintf("my Area%d_%d", i, j),
					Type:        fmt.Sprintf("my Type%d_%d", i, j),
					Actors:      fmt.Sprintf("my Actors%d_%d", i, j),
					Director:    fmt.Sprintf("my Director%d_%d", i, j),
					Description: fmt.Sprintf("my Description%d_%d", i, j),
					Plays: []Play{
						{
							Url: fmt.Sprintf("detail play1: %v,%v", i, j),
						},
						{
							Url: fmt.Sprintf("detail play2: %v,%v", i, j),
						},
					},
				}
				if err := d.Create(); err != nil {
					t.Logf("count: %v\n", count)
				}
				count++
			}
		}

	})
	// }
}

func TestGetDetail(t *testing.T) {
	mydebug.InitDB()
	database.DB.AutoMigrate(new(Detail))

	t.Run("TestGetDetail1", func(t *testing.T) {
		gotD, err := GetDetail(1)
		t.Logf("err: %v\n", err)
		jo, _ := json.Marshal(gotD)
		fmt.Printf("jo: %v\n", string(jo))
		t.Logf("gotD: %v\n", *gotD)
		t.Logf("gotD.Plays: %v\n", gotD.Plays)
	})
}

func TestDetail_CC(t *testing.T) {
	a := make(map[string]string)
	a[""] = "OK"
	s := a[""]
	fmt.Printf("s: %v\n", s)
}
